/**
 * Created by showTime on 2017/9/13.
 */
$.daterRangeDefine = function (id, formart,day) {
  //  $(id).find('span').html(moment().subtract(1, 'hours').format('YYYY-MM-DD HH:mm') + '~' + moment().format('YYYY-MM-DD HH:mm'));
    $(id).daterangepicker({
        maxDate: moment(), //最大时间
        dateLimit: {
            days: day||7
        }, //起止时间的最大间隔
        showDropdowns: true,
        showWeekNumbers: false, //是否显示第几周
        timePicker: true, //是否显示小时和分钟
        timePicker12Hour: false, //是否使用12小时制来显示时间
        ranges: {
            '最近1小时': [moment().subtract(1, 'hours'), moment()],
            '今日': [moment().startOf('day'), moment()],
            '昨日': [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')],
            '最近7日': [moment().subtract(6, 'days'), moment()]
        },
        opens: 'right', //日期选择框的弹出位置
        buttonClasses: ['btn'],
        applyClass: 'btn-success',
        cancelClass: 'btn-minor',
        format: formart || 'YYYY-MM-DD HH:mm',
        locale: {
            applyLabel: '确定',
            cancelLabel: '取消',
            fromLabel: '起始时间',
            toLabel: '结束时间',
            customRangeLabel: '自定义',
            daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
            monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
                '七月', '八月', '九月', '十月', '十一月', '十二月'],
            firstDay: 1
        }
    }, function (start, end, label) {
        // 格式化日期显示框
       // $(id).find('span').html(start.subtract(1, 'hours').format('YYYY-MM-DD HH:mm') + '~' + end.format('YYYY-MM-DD HH:mm'));
    });


    $('.daterangepicker').width('512px')

}

function setDate(tData){
        var myHour=  tData.getHours();       //获取当前小时数(0-23)
        var myMin=   tData.getMinutes();
        if(myHour<10){
            myHour="0"+myHour;
        }
        if(myMin<10){
            myMin="0"+myMin;
        }
        var myTime=' '+myHour+":"+myMin;
        var myMonth= tData.getMonth()+1;
        if(myMonth<10){
            myMonth="0"+myMonth;
        }
       var myDate=tData.getDate();
        if(myDate<10){
            myDate="0"+myDate;
        }

    var deteStr= tData.getFullYear()+'-'+myMonth+'-'+myDate;
       return  deteStr;
    }

function GetDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    return dd;
}

function setInitTime(id){
    var dateStr_7=setDate(GetDateStr(-8));
    var dateStr=setDate(GetDateStr(-1));
    var val =dateStr_7+" 00:00"+"-"+dateStr+" 23:59";
    $(id).val(val)
}
 function setInitTime2(id){//设置时间快速设置
        var tData= new Date()
        var myHour=  tData.getHours();       //获取当前小时数(0-23)
        var myMin=   tData.getMinutes();
        if(myHour<10){
            myHour="0"+myHour;
        }
        if(myMin<10){
            myMin="0"+myMin;
        }
        var myTime=' '+myHour+":"+myMin;
        var myMonth= tData.getMonth()+1;
        if(myMonth<10){
            myMonth="0"+myMonth;
        }
       var myDate=tData.getDate();
        if(myDate<10){
            myDate="0"+myDate;
        }
        var val = tData.getFullYear()+'-'+myMonth+'-'+myDate+' 00:00'+'-'+tData.getFullYear()+'-'+myMonth+'-'+myDate+myTime
        $(id).val(val)//页面通用id，时间插件设置初始值
      
    }
